

import os
import string
import commands
from appium import webdriver
import time
import datetime

class LaunchLcm(object):
    PLATFORM_NAME = 'Android'
    PLATFORM_VERSION = string.strip(commands.getoutput('adb shell getprop ro.build.version.release'))  # 获取手机系统版本
    DEVICE_NAME = string.strip(commands.getoutput('adb shell getprop ro.serialno'))  # 获取手机序列号
    PHONE_NAME = string.strip(commands.getoutput('adb shell getprop ro.build.id'))

    def __init__(self, app, appPackage, appActivity):
        #第一个 def __init__(self):
        print '##########Begin#################'
        # 建立字典,储存测试设备的信息
        desired_caps = {}
        desired_caps['platformName'] = self.PLATFORM_NAME
        desired_caps['platformVersion'] = self.PLATFORM_VERSION
        desired_caps['deviceName'] = self.DEVICE_NAME
        desired_caps['app'] = app
        desired_caps['appPackage'] = appPackage
        desired_caps['appActivity'] = appActivity
        desired_caps['noReset'] = True
        desired_caps['unicodeKeyboard'] = True
        desired_caps['resetKeyboard'] = True

        # 设置驱动器
        driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
        driver.implicitly_wait(60)
        self.driver = driver
        self.appActivity = appActivity


    # 输出当前时间
    def get_current_time(self):
        return datetime.datetime.strptime(str(datetime.datetime.now()), '%Y-%m-%d %H:%M:%S.%f')

    #关闭应用程序
    def clear_env(self):
        print '##########End###################'
        #os.system('adb shell am force-stop %s' % self.appActivity)
        self.driver.quit()


if __name__ == '__main__':
    Lcm= LaunchLcm(app='/apk/lcm_1211.apk', appPackage='com.',
                        appActivity='com')
    #Lcm.调1个日志系统
    for i in range(10):
        Lcm.get_current_time()